﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：源文件导入
 */

var userdefault = {};
var acceptClick;
var keyValue = '';
var bootstrap = function ($, learun) {
    "use strict";
    var selectedRow = learun.frameTab.currentIframe().selectedRow;
    var page = {
        init: function () {
            userdefault = learun.clientdata.get(['userinfo']);
            page.bind();
            page.initData();
            if (!!selectedRow) {
                $('#code').attr('readonly', 'readonly');
            }
        },
        bind: function () {
            $('#usecarXls').lrUploader({isView: false, extensions: "xls,xlsx"});
            $('#budgetexcuteXls').lrUploader({isView: false, extensions: "xls,xlsx"});
            $('#budgettotalXls').lrUploader({isView: false, extensions: "xls,xlsx"});
            $('#hoteldataXls').lrUploader({isView: false, extensions: "xls,xlsx"});
            $('#assetdataXls').lrUploader({isView: false, extensions: "xls,xlsx"});
            $('#assettotalXls').lrUploader({isView: false, extensions: "xls,xlsx"});
            $('#finalaccountXls').lrUploader({isView: false, extensions: "xls,xlsx"});

            // 公司选择
            $('#companyId').lrselect({
                type: 'tree',
                // placeholder: '请选择机构',
                maxHeight: 300,
                // 是否允许搜索
                allowSearch: true,
            });
            $('#companyId').lrselectRefresh({
                // 访问数据接口地址
                url: config.base_server() + 'companys/tree?access_token=' + config.getToken().access_token,
                // 访问数据接口参数
                param: {parentId: '0'}
            }).lrselectSet(userdefault.companyId)
        },
        initData: function () {
            if (!!selectedRow) {
                keyValue = selectedRow.id;
                $('#form').lrSetFormData(selectedRow);
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        if (!$('#form').lrValidform()) {
            return false;
        }
        var postData = $('#form').lrGetFormData(keyValue);

        $.lrSaveForm(config.base_server() + 'sourcefileimports/saveOrUpdate?access_token=' + config.getToken().access_token + '&keyValue=' + keyValue, JSON.stringify(postData), function (res) {
            // 保存成功后才回调
            if (!!callBack) {
                callBack();
            }
        });
    };
    page.init();
}
